// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import zombie.characters.IsoLivingCharacter;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.inventory.types.HandWeapon;
import zombie.network.packets.INetworkPacket;

public class AttackVars implements INetworkPacket {
    private boolean isBareHeadsWeapon;
    public MovingObject targetOnGround = new MovingObject();
    public boolean bAimAtFloor;
    public boolean bCloseKill;
    public boolean bDoShove;
    public float useChargeDelta;
    public int recoilDelay;
    public final ArrayList<HitInfo> targetsStanding = new ArrayList();
    public final ArrayList<HitInfo> targetsProne = new ArrayList();

    public void setWeapon(HandWeapon weapon) {
        this.isBareHeadsWeapon = "BareHands".equals(weapon.getType());
    }

    public HandWeapon getWeapon(IsoLivingCharacter owner) {
        return !this.isBareHeadsWeapon && owner.getUseHandWeapon() != null ? owner.getUseHandWeapon() : owner.bareHands;
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        byte byte0 = b.get();
        this.isBareHeadsWeapon = (byte0 & 1) != 0;
        this.bAimAtFloor = (byte0 & 2) != 0;
        this.bCloseKill = (byte0 & 4) != 0;
        this.bDoShove = (byte0 & 8) != 0;
        this.targetOnGround.parse(b, connection);
        this.useChargeDelta = b.getFloat();
        this.recoilDelay = b.getInt();
        byte byte1 = b.get();
        this.targetsStanding.clear();

        for (int int0 = 0; int0 < byte1; int0++) {
            HitInfo hitInfo0 = new HitInfo();
            hitInfo0.parse(b, connection);
            this.targetsStanding.add(hitInfo0);
        }

        byte1 = b.get();
        this.targetsProne.clear();

        for (int int1 = 0; int1 < byte1; int1++) {
            HitInfo hitInfo1 = new HitInfo();
            hitInfo1.parse(b, connection);
            this.targetsProne.add(hitInfo1);
        }
    }

    @Override
    public void write(ByteBufferWriter b) {
        byte byte0 = 0;
        byte0 = (byte)(byte0 | (byte)(this.isBareHeadsWeapon ? 1 : 0));
        byte0 = (byte)(byte0 | (byte)(this.bAimAtFloor ? 2 : 0));
        byte0 = (byte)(byte0 | (byte)(this.bCloseKill ? 4 : 0));
        byte0 = (byte)(byte0 | (byte)(this.bDoShove ? 8 : 0));
        b.putByte(byte0);
        this.targetOnGround.write(b);
        b.putFloat(this.useChargeDelta);
        b.putInt(this.recoilDelay);
        byte byte1 = (byte)Math.min(100, this.targetsStanding.size());
        b.putByte(byte1);

        for (int int0 = 0; int0 < byte1; int0++) {
            HitInfo hitInfo0 = (HitInfo)this.targetsStanding.get(int0);
            hitInfo0.write(b);
        }

        byte1 = (byte)Math.min(100, this.targetsProne.size());
        b.putByte(byte1);

        for (int int1 = 0; int1 < byte1; int1++) {
            HitInfo hitInfo1 = (HitInfo)this.targetsProne.get(int1);
            hitInfo1.write(b);
        }
    }

    @Override
    public int getPacketSizeBytes() {
        int int0 = 11 + this.targetOnGround.getPacketSizeBytes();
        byte _byte = (byte)Math.min(100, this.targetsStanding.size());

        for (int int1 = 0; int1 < _byte; int1++) {
            HitInfo hitInfo0 = (HitInfo)this.targetsStanding.get(int1);
            int0 += hitInfo0.getPacketSizeBytes();
        }

        _byte = (byte)Math.min(100, this.targetsProne.size());

        for (int int2 = 0; int2 < _byte; int2++) {
            HitInfo hitInfo1 = (HitInfo)this.targetsProne.get(int2);
            int0 += hitInfo1.getPacketSizeBytes();
        }

        return int0;
    }

    @Override
    public String getDescription() {
        String string0 = "";
        byte _byte = (byte)Math.min(100, this.targetsStanding.size());

        for (int int0 = 0; int0 < _byte; int0++) {
            HitInfo hitInfo0 = (HitInfo)this.targetsStanding.get(int0);
            string0 = string0 + hitInfo0.getDescription();
        }

        String string1 = "";
        _byte = (byte)Math.min(100, this.targetsProne.size());

        for (int int1 = 0; int1 < _byte; int1++) {
            HitInfo hitInfo1 = (HitInfo)this.targetsProne.get(int1);
            string1 = string1 + hitInfo1.getDescription();
        }

        return "\n\tHitInfo [ isBareHeadsWeapon="
            + this.isBareHeadsWeapon
            + " bAimAtFloor="
            + this.bAimAtFloor
            + " bCloseKill="
            + this.bCloseKill
            + " bDoShove="
            + this.bDoShove
            + " useChargeDelta="
            + this.useChargeDelta
            + " recoilDelay="
            + this.recoilDelay
            + "\n\t  targetOnGround:"
            + this.targetOnGround.getDescription()
            + "\n\t  targetsStanding=["
            + string0
            + "](size="
            + this.targetsStanding.size()
            + ")\n\t  targetsProne=["
            + string1
            + "](size="
            + this.targetsProne.size()
            + ")]";
    }

    public void copy(AttackVars original) {
        this.isBareHeadsWeapon = original.isBareHeadsWeapon;
        this.targetOnGround = original.targetOnGround;
        this.bAimAtFloor = original.bAimAtFloor;
        this.bCloseKill = original.bCloseKill;
        this.bDoShove = original.bDoShove;
        this.useChargeDelta = original.useChargeDelta;
        this.recoilDelay = original.recoilDelay;
        this.targetsStanding.clear();

        for (HitInfo hitInfo0 : original.targetsStanding) {
            this.targetsStanding.add(hitInfo0);
        }

        this.targetsProne.clear();

        for (HitInfo hitInfo1 : original.targetsProne) {
            this.targetsProne.add(hitInfo1);
        }
    }

    public void clear() {
        this.targetOnGround.setMovingObject(null);
        this.targetsStanding.clear();
        this.targetsProne.clear();
    }
}
